Skip to content

chore: reconcile downstream version dependencies on job success#1085

Merged
adityachoudhari26 merged 2 commits intomainfrom
trigger-version-downstream-deps
Apr 29, 2026
Merged

chore: reconcile downstream version dependencies on job success#1085
adityachoudhari26 merged 2 commits intomainfrom
trigger-version-downstream-deps

Conversation

@adityachoudhari26
Copy link
Copy Markdown
Member

@adityachoudhari26 adityachoudhari26 commented Apr 29, 2026

fixes #1079

Summary by CodeRabbit

Release Notes

  • New Features

    • Introduced automatic downstream dependency dispatching when deployment jobs complete successfully, enabling proper orchestration of dependent deployments across environments.
  • Bug Fixes

    • Improved query result determinism by applying consistent ordering to deployment-related queries.

Copilot AI review requested due to automatic review settings April 29, 2026 19:33
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 29, 2026

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 0dc8bb16-2c58-4a21-bc0e-2b70c00acd01

📥 Commits

Reviewing files that changed from the base of the PR and between 8967385 and c184917.

📒 Files selected for processing (6)
  • apps/workspace-engine/pkg/db/computed_resources.sql.go
  • apps/workspace-engine/pkg/db/deployments.sql.go
  • apps/workspace-engine/pkg/db/queries/computed_resources.sql
  • apps/workspace-engine/pkg/db/queries/deployments.sql
  • apps/workspace-engine/svc/controllers/jobdispatch/dispatch_dependency_downstream.go
  • apps/workspace-engine/svc/controllers/jobdispatch/setters_postgres.go

Disabled knowledge base sources:

  • Linear integration is disabled

You can enable these sources in your CodeRabbit configuration.


📝 Walkthrough

Walkthrough

Introduces a new database query to fetch distinct release targets for a deployment-resource pair across environments, with supporting generated code. Adds a downstream dependency dispatch routine in the job controller that queries upstream jobs and enqueues release evaluations for affected downstream deployments when a job succeeds. Also adds deterministic ordering to an existing deployment dependency query.

Changes

Cohort / File(s) Summary
Database Queries—Computed Resources
apps/workspace-engine/pkg/db/queries/computed_resources.sql, apps/workspace-engine/pkg/db/computed_resources.sql.go
Introduces new GetReleaseTargetsForDeploymentAndResource query to retrieve distinct release targets for a (deployment, resource) pair across all environments, with generated parameter and row structs to support the query execution.
Database Queries—Deployments
apps/workspace-engine/pkg/db/queries/deployments.sql, apps/workspace-engine/pkg/db/deployments.sql.go
Adds deterministic ORDER BY dv.deployment_id clause to GetDeploymentsWithVersionsDependingOn query and removes descriptive comment from GetDeploymentDependenciesByVersionID (no functional change to that method).
Job Dispatch Controller
apps/workspace-engine/svc/controllers/jobdispatch/dispatch_dependency_downstream.go
Introduces new unexported dispatchDependencyDownstreamTargets function that queries upstream job context, retrieves downstream deployments with version dependencies, fetches their release targets, and enqueues desired release evaluations for affected deployment-resource-environment combinations.
Job Update Flow
apps/workspace-engine/svc/controllers/jobdispatch/setters_postgres.go
Integrates downstream dependency dispatch into UpdateJob control flow, invoking the new dispatch routine conditionally when job status transitions to Successful.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested reviewers

  • jsbroks

Poem

🐰 A query hops forth, with targets in sight,
When jobs succeed downstream, dispatch takes flight,
Release evaluations bloom from dependency chains,
Through environments vast, down deployment lanes! 🌱

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch trigger-version-downstream-deps

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
Review rate limit: 0/1 reviews remaining, refill in 60 minutes.

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR ensures deployment-version dependency gates get re-evaluated promptly by enqueueing downstream desired-release reconciliations when an upstream job becomes successful (i.e., when the “current release” for a resource can change).

Changes:

  • Trigger downstream dependency fan-out from PostgresSetter.UpdateJob when the job status transitions to successful.
  • Add dispatchDependencyDownstreamTargets to find downstream deployments (via version dependencies) and enqueue desired-release evaluations for matching (deployment, environment, resource) release targets.
  • Add a new sqlc query GetReleaseTargetsForDeploymentAndResource (and generated Go) to enumerate downstream release targets for a specific deployment/resource pair.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.

File Description
apps/workspace-engine/svc/controllers/jobdispatch/setters_postgres.go Calls the new downstream-dispatcher when a job becomes successful.
apps/workspace-engine/svc/controllers/jobdispatch/dispatch_dependency_downstream.go Implements downstream dependency discovery + enqueueing desired-release eval work items.
apps/workspace-engine/pkg/db/queries/computed_resources.sql Adds a query to list all release targets for a (deployment, resource) across environments.
apps/workspace-engine/pkg/db/computed_resources.sql.go sqlc-generated Go for the new computed_resources query.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

if err != nil {
return fmt.Errorf(
"get release targets for downstream deployment %s: %w",
downstreamDepID,
Copy link

Copilot AI Apr 29, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The error format string uses %s with downstreamDepID (a uuid.UUID), which will produce a malformed %!s(uuid.UUID=...) message. Use downstreamDepID.String() (or %v) so the deployment ID is correctly rendered in errors/logs.

Suggested change
downstreamDepID,
downstreamDepID.String(),

Copilot uses AI. Check for mistakes.
Comment on lines +53 to +56
downstreamDeps, err := queries.GetDeploymentsWithVersionsDependingOn(ctx, release.DeploymentID)
if err != nil {
return fmt.Errorf("get deployments with versions depending on: %w", err)
}
Copy link

Copilot AI Apr 29, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GetDeploymentsWithVersionsDependingOn is not scoped to the upstream job's workspace, but you enqueue downstream desired-release evals using the upstream wsID for every item. If a deployment version dependency can reference deployments across workspaces (schema doesn't appear to prevent it), this could enqueue work items into the wrong workspace / leak IDs. Consider scoping the query by workspace (e.g., add workspace_id param and filter on deployment_version.workspace_id or join deployment) or fetching each downstream deployment's workspace ID and using that when enqueueing.

Copilot uses AI. Check for mistakes.
Comment on lines +65 to +91
var params []events.DesiredReleaseEvalParams

for _, downstreamDepID := range downstreamDeps {
rts, err := queries.GetReleaseTargetsForDeploymentAndResource(
ctx,
db.GetReleaseTargetsForDeploymentAndResourceParams{
DeploymentID: downstreamDepID,
ResourceID: release.ResourceID,
},
)
if err != nil {
return fmt.Errorf(
"get release targets for downstream deployment %s: %w",
downstreamDepID,
err,
)
}
for _, rt := range rts {
params = append(params, events.DesiredReleaseEvalParams{
WorkspaceID: wsIDStr,
ResourceID: rt.ResourceID.String(),
EnvironmentID: rt.EnvironmentID.String(),
DeploymentID: rt.DeploymentID.String(),
})
}
}

Copy link

Copilot AI Apr 29, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This does one DB query per downstream deployment (GetReleaseTargetsForDeploymentAndResource inside the loop). If a deployment has many downstream dependents, this becomes an N+1 query pattern. Consider adding a single sqlc query that accepts downstream_deployment_ids (uuid[]) + resource_id and returns all (deployment, environment, resource) targets in one round-trip, then build params from that result.

Suggested change
var params []events.DesiredReleaseEvalParams
for _, downstreamDepID := range downstreamDeps {
rts, err := queries.GetReleaseTargetsForDeploymentAndResource(
ctx,
db.GetReleaseTargetsForDeploymentAndResourceParams{
DeploymentID: downstreamDepID,
ResourceID: release.ResourceID,
},
)
if err != nil {
return fmt.Errorf(
"get release targets for downstream deployment %s: %w",
downstreamDepID,
err,
)
}
for _, rt := range rts {
params = append(params, events.DesiredReleaseEvalParams{
WorkspaceID: wsIDStr,
ResourceID: rt.ResourceID.String(),
EnvironmentID: rt.EnvironmentID.String(),
DeploymentID: rt.DeploymentID.String(),
})
}
}
rts, err := queries.GetReleaseTargetsForDeploymentsAndResource(
ctx,
db.GetReleaseTargetsForDeploymentsAndResourceParams{
DeploymentIds: downstreamDeps,
ResourceID: release.ResourceID,
},
)
if err != nil {
return fmt.Errorf("get release targets for downstream deployments: %w", err)
}
params := make([]events.DesiredReleaseEvalParams, 0, len(rts))
for _, rt := range rts {
params = append(params, events.DesiredReleaseEvalParams{
WorkspaceID: wsIDStr,
ResourceID: rt.ResourceID.String(),
EnvironmentID: rt.EnvironmentID.String(),
DeploymentID: rt.DeploymentID.String(),
})
}

Copilot uses AI. Check for mistakes.
Comment on lines +110 to +116
// Deployment-version dependency gates only react to "current release"
// changes, which only happen when a job becomes successful.
if status == oapi.JobStatusSuccessful {
if err := dispatchDependencyDownstreamTargets(ctx, s.Queue, jobIDUUID); err != nil {
return fmt.Errorf("dispatch dependency downstream targets: %w", err)
}
}
Copy link

Copilot AI Apr 29, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New behavior is introduced here (enqueueing desired-release reconciliations for downstream deployment-version dependencies when a job becomes successful), but there doesn't appear to be any test coverage asserting the downstream fan-out and enqueue behavior. Please add a unit/integration test that exercises a job status transition to successful and verifies the expected desired-release work items are enqueued for downstream deployments on the same resource.

Copilot uses AI. Check for mistakes.
@adityachoudhari26 adityachoudhari26 merged commit c747f21 into main Apr 29, 2026
8 of 9 checks passed
@adityachoudhari26 adityachoudhari26 deleted the trigger-version-downstream-deps branch April 29, 2026 19:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Deployment dependencies: re-trigger dependent release targets on upstream changes

2 participants